using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using WPF_DbCenter.CommonMethod;
using System.Security;

namespace WPF_DbCenter.UI
{
    /// <summary>
    /// Interaction logic for CreateEmptyDb.xaml
    /// </summary>

    public partial class CreateEmptyDb : BaseUI.BaseFadeDialog
    {
        public delegate void Del_CreateDbAfterSuccesful(string fullPath,string pwd);
        public Del_CreateDbAfterSuccesful CreateDbAfterSuccesful;

        public CreateEmptyDb()
        {
            InitializeComponent();

            WindowStartupLocation = WindowStartupLocation.CenterScreen;
        }

        private void butClose_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void butCreate_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtDbName.Text))
            {
                MessageBox.Show("Please input db name");
                return;
            }
            if (txtPwd.Password != txtConfirmPwd.Password)
            {
                MessageBox.Show("Two passwords are not same,please try again");
                return;
            }

            string dbName=txtDbName.Text;
            string pwd=txtPwd.Password;
            bool isEncrypted = (bool)this.checkBox1.IsChecked;

            if (App.MainEngineer.CreateDataBase(dbName, pwd, isEncrypted))
            {
                MessageBox.Show(string.Format("Create {0} successful", dbName));
                if (CreateDbAfterSuccesful != null)
                {
                    CreateDbAfterSuccesful(dbName, pwd);
                }

                Close();
            }
               
        }

        private void butSelect_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog();
            sf.Filter = AppEntry.SQLCE_FILE_FILTER;
            if (sf.ShowDialog() == true)
            {
                txtDbName.Text = sf.FileName;
            }
        }

    }
}